package com.et114.modules.cust.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.et114.core.action.BaseDispatchAction;
import com.et114.modules.cust.form.Mng_LeadForm;
import com.et114.modules.cust.services.IMng_CustService;
import com.et114.modules.cust.services.Mng_CustServiceImp;
import com.et114.modules.cust.vo.CustInfoVo;
import com.et114.modules.cust.vo.LeadVo;
import com.et114.modules.org.services.UserManager;
import com.et114.modules.org.vo.UserVo;

/**
 * 潜在客户管理:信息查询
 * 
 * @author zhiweip
 * @version 1.0
 * @created 09-十一月-2010 23:03:48
 */
public class Mng_LeadQueryAction extends BaseDispatchAction {
	
	private IMng_CustService	mng_CustService	= ( Mng_CustServiceImp ) getBean ( "mng_CustService" );
	
	public void finalize ( ) throws Throwable {
		
	}
	
	@ Override
	public ActionForward unspecified ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception { 
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null) );
		Mng_LeadForm cform = ( Mng_LeadForm ) form;
		 
		request.setAttribute ( "OPTIONS" , mng_CustService.getItemTypes ( ) ) ;
		return mapping.findForward ( "queryLeadDataList" );
	}
	
	// Mng_LeadForm
	public ActionForward leadQuery ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception { 
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null) );
		request.setAttribute ( "OPTIONS" , mng_CustService.getItemTypes ( ) ) ;
		
		
		Mng_LeadForm cform = ( Mng_LeadForm ) form;
		LeadVo vo = cform.getLead ( );
		vo.setPageNum ( cform.getPageNum ( ) );
		vo.setPageSize ( cform.getPageSize ( ) );
		logger.debug  ("================="+vo.getWorker ( ));
		request.setAttribute ( "lead" , vo ); 
		request.setAttribute ( "DataList" , mng_CustService
				.queryLeadDataList ( vo ) );
		return mapping.findForward ( "queryLeadDataList" );
	}
	
	public ActionForward leadsQuery ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception { 
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null) );
		request.setAttribute ( "OPTIONS" , mng_CustService.getItemTypes ( ) ) ;
		
		
		Mng_LeadForm cform = ( Mng_LeadForm ) form;
		LeadVo vo = cform.getLead ( );
		vo.setPageNum ( cform.getPageNum ( ) );
		vo.setPageSize ( cform.getPageSize ( ) );
		request.setAttribute ( "lead" , vo );
		request.setAttribute ( "DataList" , mng_CustService
				.queryLeadDataList ( vo ) );
		return mapping.findForward ( "queryLeadDataList" );
	}
	
	public ActionForward toModify ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception {
		
		return mapping.findForward ( "toModify" );
	}
	
	/**
	 * 客户详细信息
	 */
	public ActionForward view ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception {
		String custid = request.getParameter ( "custid" );
		Mng_LeadForm cform = ( Mng_LeadForm ) form;
		LeadVo cust = cform.getLead ( );
		cust.setCustid ( new Integer ( custid ) );
		CustInfoVo info = new CustInfoVo ( );
		info.setCustid ( cust.getCustid ( ) );
		cust = mng_CustService.loadLeadCust ( cust );
		request.setAttribute ( "BASEINFO" , cust );
		
		if ( cust.getLeaderid ( ) != null ) {
			LeadVo ivo = new LeadVo ( );
			ivo.setLeaderid ( cust.getLeaderid ( ) );
			request.setAttribute ( "LeaderINTENT" , mng_CustService
					.queryLeaderIntentList ( ivo ) );
			request.setAttribute ( "LeaderINTENTLOG" ,mng_CustService.query_PUB_LEADER_LOG (ivo ));
		}
		// CustDetail
		return mapping.findForward ( "CustDetail" );
	}
	
	public ActionForward toExpXls ( ActionMapping mapping , ActionForm form ,
			HttpServletRequest request , HttpServletResponse response )
			throws Exception { 
		
		Mng_LeadForm cform = ( Mng_LeadForm ) form;
		LeadVo vo = cform.getLead ( ); 
		mng_CustService.toExpXls ( vo,response);
		return null;
	}
	
}